{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Day of the Week"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: dayOfTheWeek"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #一周中的第几天"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个日期，请你设计一个算法来判断它是对应一周中的哪一天。</p>\n",
    "\n",
    "<p>输入为三个整数：<code>day</code>、<code>month</code> 和&nbsp;<code>year</code>，分别表示日、月、年。</p>\n",
    "\n",
    "<p>您返回的结果必须是这几个值中的一个&nbsp;<code>{&quot;Sunday&quot;, &quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;}</code>。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>day = 31, month = 8, year = 2019\n",
    "<strong>输出：</strong>&quot;Saturday&quot;\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>day = 18, month = 7, year = 1999\n",
    "<strong>输出：</strong>&quot;Sunday&quot;\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>day = 15, month = 8, year = 1993\n",
    "<strong>输出：</strong>&quot;Sunday&quot;\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li>给出的日期一定是在&nbsp;<code>1971</code> 到&nbsp;<code>2100</code>&nbsp;年之间的有效日期。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [day-of-the-week](https://leetcode.cn/problems/day-of-the-week/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [day-of-the-week](https://leetcode.cn/problems/day-of-the-week/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['31\\n8\\n2019', '18\\n7\\n1999', '15\\n8\\n1993']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import datetime\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return datetime.date(year,month,day).strftime('%A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return datetime.date(year, month, day).strftime('%A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import time\n",
    "import datetime\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:  \n",
    "        #print(help(datetime))      \n",
    "        #print(time.asctime()[0])\n",
    "        #print(time.localtime(),time.localtime()[6])\n",
    "        t=str(year)+'-'+str(month)+'-'+str(day)\n",
    "        #print(time.strptime(t,\"%Y-%m-%d\"))        \n",
    "        w=[\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "        #a=time.strptime(t,\"%Y-%m-%d\")\n",
    "        #print(w[a[6]])\n",
    "        #return w[a[6]-6]\n",
    "        \n",
    "        b=datetime.date(year,month,day)\n",
    "        return w[b.weekday()-6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return datetime.date(year, month, day).strftime('%A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        import datetime\n",
    "        weekday=datetime.date(year,month,day).weekday()\n",
    "        den=[ \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",\"Sunday\"]\n",
    "        return den[weekday]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return datetime.datetime(year, month, day).strftime(\"%A\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        import datetime\n",
    "        anyday=datetime.datetime(year,month,day).strftime('%A')\n",
    "        return anyday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        lst = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        return lst[datetime.date(year, month, day).weekday()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        start = 4 - 1\n",
    "        target = 0\n",
    "        count = (year - 1971) * 365\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31]\n",
    "        for i in range (1971, year):\n",
    "            if i % 4 == 0:\n",
    "                target += 1\n",
    "        count += target\n",
    "        if (year % 4 == 0 or year % 400 == 0)and year % 100 != 0 and month > 2:\n",
    "            count += 1\n",
    "        count += sum(days[:month - 1]) + day\n",
    "        return week[(start + count) % 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        lst = [\"\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",  \"Sunday\"]\n",
    "        return lst[datetime.date(year, month, day).isoweekday()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        date1=datetime.date(year,month,day)\n",
    "        date2=datetime.date(1,1,1)\n",
    "        offset=(date1-date2).days\n",
    "        offset%=7\n",
    "        lis=[ \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",\"Sunday\"]\n",
    "        return lis[offset]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "\n",
    "      week_day_dict = {\n",
    "        0:\"Sunday\",\n",
    "        1:\"Monday\",\n",
    "        2:\"Tuesday\",\n",
    "        3:\"Wednesday\",\n",
    "        4:\"Thursday\",\n",
    "        5:\"Friday\",\n",
    "        6:\"Saturday\"\n",
    "      }\n",
    "\n",
    "      date1 = datetime.datetime(year,month,day).strftime(\"%w\")\n",
    "\n",
    "      return week_day_dict[int(date1)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        days=[0,31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        res=[\"Thursday\",\"Friday\",\"Saturday\",\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\"]\n",
    "\n",
    "        def isyear(year):\n",
    "            if year % 400 ==0:return True\n",
    "            else:\n",
    "                if year % 100 ==0:return False\n",
    "                if year % 4 ==0:return True\n",
    "            return False\n",
    "        for y in range(1971,year):\n",
    "            if isyear(y):\n",
    "                days[0]=days[0]+366\n",
    "            else:\n",
    "                days[0]=days[0]+365\n",
    "\n",
    "        if isyear(year):days[2]=29\n",
    "        for i in range(1,month):\n",
    "            days[0]=days[0]+days[i]\n",
    "\n",
    "        days[0]=days[0]+day\n",
    "        return res[days[0]%7]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        #1970-12-31 Thursday\n",
    "        Month =[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        week = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']\n",
    "        days = 365*(year-1971)+(year-1969)//4\n",
    "        days += sum(Month[:month-1])\n",
    "        days += day\n",
    "        if month > 2 and (year%400 == 0 or (year%4==0 and year%100!=0)):\n",
    "            days += 1\n",
    "        days += 3\n",
    "        return week[days%7]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\r\n",
    "        import datetime\r\n",
    "        return datetime.date(year, month, day).strftime('%A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        偏移 = 365*(year-1971) + (year-1)//4-1970//4\n",
    "        字典 = {0:0, 1:31, 2:59, 3:90, 4:120, 5:151, 6:181, 7:212, 8:243, 9:273, 10:304, 11:334, 12:365}\n",
    "        偏移 += 字典[month-1] + (1 if month > 2 and year!=2100 and year%4 == 0 else 0) + day + 4\n",
    "        偏移 %= 7\n",
    "        日期表 = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "        return 日期表[偏移]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "WEEKDAY = (\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\")\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return WEEKDAY[date(year, month, day).weekday()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        day1 = 1\n",
    "        month1 = 1\n",
    "        year1 = 1971\n",
    "        week1 = 'Friday'\n",
    "\n",
    "        month_of_day = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        weeklist = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "\n",
    "        days = 0\n",
    "        for i in range(year1, year):\n",
    "            days += 365 + self.isleapyear(i)\n",
    "\n",
    "        if self.isleapyear(year):\n",
    "            month_of_day[1] += 1\n",
    "        for j in range(month1 - 1, month - 1):\n",
    "            days += month_of_day[j]\n",
    "\n",
    "        days += day - day1 + 4\n",
    "        last = int((days % 7))\n",
    "        return weeklist[last]\n",
    "\n",
    "\n",
    "    def isleapyear(self, year):\n",
    "        return year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)\n",
    "\n",
    "\n",
    "\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import datetime\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week=datetime.datetime(year,month,day).strftime(\"%w\")\n",
    "        week_name=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']\n",
    "        week1=week_name[int(week)]\n",
    "        return week1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    # 1971年1月1号 周五，除以 7 之后+4，就是那天的周几\n",
    "    # 判断闰年\n",
    "    def isLeapYear(self, year):\n",
    "        return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)\n",
    "\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        weeks = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "        # weeks = [\"Friday\", \"Saturday\",\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\"]\n",
    "        month_day = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        # 目标日期距离 1971 年是多少天\n",
    "        days=0\n",
    "        # 1。算整年天数\n",
    "        for i in range(1971,year):\n",
    "            if self.isLeapYear(i):\n",
    "                days+=366\n",
    "            else:\n",
    "                days+=365\n",
    "        # print('加完年后的天数', days)\n",
    "        # 算月份的天数，如果 year 是闰年，且月份大于 2，要+1，从1 月加 起\n",
    "        day2=0\n",
    "        for i in range(month):\n",
    "            day2+=month_day[i]\n",
    "\n",
    "        if self.isLeapYear(year) and month>2:\n",
    "            day2+=1\n",
    "        # print('月份加完',day2)\n",
    "        days=days+day2+day\n",
    "        print(days)\n",
    "        j=(days+4)%7\n",
    "        # print(j)\n",
    "        return weeks[j]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        nums = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        weekday_name = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        d, m, y = day, month - 1, year - 1\n",
    "        days_y = y * 365 + y // 4 - y // 100 + y // 400\n",
    "        leap = 1 if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0 else 0\n",
    "        if leap:\n",
    "            if month > 2:\n",
    "                days_m = sum(nums[:m]) + 1\n",
    "            else:\n",
    "                days_m = sum(nums[:m])\n",
    "        else:\n",
    "            days_m = sum(nums[:m])\n",
    "\n",
    "        days = days_y + days_m + d\n",
    "        week_day = days % 7 - 1\n",
    "        return weekday_name[week_day]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]\n",
    "        days = 0\n",
    "        days += 365 * (year - 1971) + (year - 1969) // 4\n",
    "        days += sum(monthDays[:month-1])\n",
    "        if (year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)) and month >= 3:\n",
    "            days += 1\n",
    "        days += day\n",
    "        return week[(days + 3) % 7]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        import datetime\n",
    "\n",
    "        days_of_week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        date = datetime.datetime(year, month, day)\n",
    "        return days_of_week[date.weekday()]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        import datetime\n",
    "        anyday=datetime.datetime(year,month,day).strftime('%A')\n",
    "        return anyday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        day_week = {1:\"Friday\",\n",
    "            2:\"Saturday\",\n",
    "            3:\"Sunday\",\n",
    "            4:\"Monday\",\n",
    "            5:\"Tuesday\",\n",
    "            6:\"Wednesday\",\n",
    "            0:\"Thursday\"}\n",
    "        days = day\n",
    "        for y in range(1971,year):\n",
    "            days += 365\n",
    "            if y % 4 == 0:\n",
    "                if y % 100 == 0:\n",
    "                    if y % 400 == 0:\n",
    "                        days += 1\n",
    "                else:\n",
    "                    days += 1\n",
    "        month_30 = [4,6,9,11]\n",
    "        feb = 28\n",
    "        if year % 4 == 0:\n",
    "            if year % 100 == 0:\n",
    "                if year % 400 == 0:\n",
    "                    feb += 1\n",
    "            else:\n",
    "                feb += 1\n",
    "        for m in range(1,month):\n",
    "            if m in month_30:\n",
    "                days += 30\n",
    "            elif m == 2:\n",
    "                days += feb\n",
    "            else:\n",
    "                days += 31\n",
    "        return day_week[days % 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return date(year,month,day).strftime(\"%A\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        import datetime\n",
    "\n",
    "        days_of_week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        date = datetime.datetime(year, month, day)\n",
    "        return days_of_week[date.weekday()]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        lists=[\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "        count=0\n",
    "        for i in range(1971,year):\n",
    "            if (i%4==0 and i%100!=0) or i%400==0:\n",
    "                count+=366\n",
    "            else:\n",
    "                count+=365\n",
    "        \n",
    "        for i in range(1,month):\n",
    "            if i in [1,3,5,7,8,10,12]:\n",
    "                count+=31\n",
    "            elif i==2:\n",
    "                if (year%4==0 and year%100!=0) or year%400==0:\n",
    "                    count+=29\n",
    "                else:\n",
    "                    count+=28\n",
    "            else:\n",
    "                count+=30\n",
    "        count+=day\n",
    "        if (count-1)%7==0:\n",
    "            return lists[5]\n",
    "        elif (count-1)%7==1:\n",
    "            return lists[6]\n",
    "        elif (count-1)%7==2:\n",
    "            return lists[0]\n",
    "        elif (count-1)%7==3:\n",
    "            return lists[1]\n",
    "        elif (count-1)%7==4:\n",
    "            return lists[2]\n",
    "        elif (count-1)%7==5:\n",
    "            return lists[3]\n",
    "        elif (count-1)%7==6:\n",
    "            return lists[4]\n",
    "                \n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        start = 4 - 1\n",
    "        target = 0\n",
    "        count = (year - 1971) * 365\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31]\n",
    "        for i in range (1971, year):\n",
    "            if i % 4 == 0:\n",
    "                target += 1\n",
    "        count += target\n",
    "        if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:\n",
    "            if month > 2:\n",
    "                count += 1\n",
    "        count += sum(days[:month - 1]) + day\n",
    "        return week[(start + count) % 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week=[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\",\"Sunday\"]\n",
    "        monthDays=[31,28,31,30,31,30,31,31,30,31,30]\n",
    "        days=0\n",
    "        days+=365*(year-1971)+(year-1969)//4\n",
    "        days+=sum(monthDays[:month-1])\n",
    "        if(year %400==0 or (year%4==0 and year%100!=0)) and month>=3:\n",
    "            days+=1\n",
    "        days+=day\n",
    "        return week[(days+3)%7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",\"Sunday\"][datetime.datetime(year,month,day).weekday()]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        def dayOfYear(date: str) -> int:\n",
    "            dd = date.split('-')\n",
    "            day = 0\n",
    "            if int(dd[0]) % 400 == 0 or (int(dd[0]) % 4 == 0 and int(dd[0]) % 100 != 0):  # 闰年\n",
    "                days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "                day += sum(days[:int(dd[1]) - 1])\n",
    "                day += int(dd[2])\n",
    "            else:\n",
    "                days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "                day += sum(days[:int(dd[1]) - 1])\n",
    "                day += int(dd[2])\n",
    "            return day\n",
    "\n",
    "        days = 0\n",
    "        for yy in range(1971, year):\n",
    "            days += dayOfYear(str(yy) + \"-12-31\")\n",
    "        days += dayOfYear(str(year) + \"-\" + str(month) + \"-\" + str(day))\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        return week[(days + 3) % 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",\"Sunday\"][datetime.datetime(year,month,day).weekday()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import datetime\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return datetime.date(year,month,day).strftime('%A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        start = 4 - 1\n",
    "        target = 0\n",
    "        count = (year - 1971) * 365\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31]\n",
    "        for i in range (1971, year):\n",
    "            if i % 4 == 0:\n",
    "                target += 1\n",
    "        count += target\n",
    "        if (year % 4 == 0 or year % 400 == 0)and year % 100 != 0 and month > 2:\n",
    "            count += 1\n",
    "        count += sum(days[:month - 1]) + day\n",
    "        return week[(start + count) % 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        day1 = 1\n",
    "        month1 = 1\n",
    "        year1 = 1971\n",
    "        week1 = 'Friday'\n",
    "\n",
    "        monthlist = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        weeklist = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",\"Sunday\"]\n",
    "\n",
    "        dayyear = 0\n",
    "        for i in range(year1, year):\n",
    "            if self.isleapyear(i):\n",
    "                dayyear += 366\n",
    "            else:\n",
    "                dayyear += 365\n",
    "\n",
    "        daymonth = 0\n",
    "        if self.isleapyear(year):\n",
    "            monthlist[1] += 1\n",
    "        for j in range(month1 - 1, month - 1):\n",
    "            daymonth += monthlist[j]\n",
    "\n",
    "        dayday = day - day1\n",
    "        sumday = dayyear + daymonth + dayday + 4\n",
    "        last = int((sumday % 7))\n",
    "        return weeklist[last]\n",
    "\n",
    "\n",
    "    def isleapyear(self, year):\n",
    "        return year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)\n",
    "\n",
    "\n",
    "\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return datetime.date(year,month,day).strftime('%A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        m = month + 12 if month <= 2 else month\n",
    "        y = year - 1 if month <= 2 else year\n",
    "        c = y // 100\n",
    "        y = y % 100\n",
    "        match (-2 * c + y + c // 4 + y // 4 + 13 * (m + 1) // 5 + day - 1) % 7:\n",
    "            case 0: return 'Sunday'\n",
    "            case 1: return 'Monday'\n",
    "            case 2: return 'Tuesday'\n",
    "            case 3: return 'Wednesday'\n",
    "            case 4: return 'Thursday'\n",
    "            case 5: return 'Friday'\n",
    "            case _: return 'Saturday'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import time\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:                \n",
    "        t=str(year)+'-'+str(month)+'-'+str(day)\n",
    "        #print(time.strptime(t,\"%Y-%m-%d\"))        \n",
    "        w=[\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "        a=time.strptime(t,\"%Y-%m-%d\")\n",
    "        #print(w[a[6]])\n",
    "        return w[a[6]-6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        day0 = 1\n",
    "        month0 = 1\n",
    "        year0 = 1971\n",
    "        res0 = 'Friday'\n",
    "        monthlist = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        # 7 -> 0\n",
    "        # 1 -> 1\n",
    "        # 2 -> 2\n",
    "        # 3 -> 3 \n",
    "        # 4 -> 4\n",
    "        # 5 -> 5\n",
    "        # 6 -> 6\n",
    "        reslist = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "\n",
    "        yeargap = 0\n",
    "        for i in range(year0, year):\n",
    "            if (i % 400 == 0) or (i % 4 == 0 and i % 100 != 0):\n",
    "                yeargap += 366\n",
    "            else:\n",
    "                yeargap += 365\n",
    "\n",
    "        monthgap = 0 # 猪头\n",
    "        for j in range(month0, month):\n",
    "            if j == 2 and ((year % 400 == 0) or (year % 4 == 0 and year % 100 != 0)):\n",
    "                monthgap += 29\n",
    "            else:\n",
    "                monthgap += monthlist[j - 1]\n",
    "            print(monthgap, j)\n",
    "\n",
    "        daygap = day - day0\n",
    "        daynum = yeargap + monthgap + daygap + 5\n",
    "        last = int(daynum % 7)\n",
    "        return reslist[last]\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "\n",
    "        #1971.1.1 Fri\n",
    "        day_list = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "        year_days_list = []\n",
    "        for y in range(1971, 2100):\n",
    "            if y%4==0:\n",
    "                year_days_list.append(366)\n",
    "            else:\n",
    "                year_days_list.append(365)\n",
    "        \n",
    "        year_days_list.append(365)\n",
    "\n",
    "        n_years = year - 1971\n",
    "        n_days_y = sum(year_days_list[:n_years])\n",
    "\n",
    "        day_11 = (n_days_y + 5)%7\n",
    "        if day_11 == 0:\n",
    "             day_11=7\n",
    "\n",
    "        if year%4!=0 or year==2100:\n",
    "            mon_list = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        else:\n",
    "            mon_list = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        \n",
    "        mon_days_past = sum(mon_list[:(month-1)]) + day-1\n",
    "\n",
    "        day_today = (day_11 + mon_days_past)%7\n",
    "\n",
    "        return day_list[day_today]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        diff = 0\n",
    "        # year\n",
    "        i = 1971\n",
    "        leap = 0\n",
    "        while i < year:\n",
    "            if (i % 4 == 0 and i % 100 != 0) or (i % 400 == 0):\n",
    "                leap += 1\n",
    "            i += 1\n",
    "        diff = (year - 1971) * 365 + leap\n",
    "        # month\n",
    "        months = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],\n",
    "        [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]]\n",
    "        if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):\n",
    "            leap = 1\n",
    "        else:\n",
    "            leap = 0\n",
    "        m = 0\n",
    "        while m < month - 1:\n",
    "            diff += months[leap][m]\n",
    "            m += 1\n",
    "        # day\n",
    "        diff += day - 1\n",
    "        diff %= 7\n",
    "\n",
    "        # answer\n",
    "        weekdays = [\"Friday\", \"Saturday\", \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\"]\n",
    "\n",
    "        return weekdays[diff]\n",
    "        \n",
    "            \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]\n",
    "        days = 0\n",
    "        days += 365* (year - 1971) + (year - 1969) // 4\n",
    "        days += sum(monthDays[:month-1])\n",
    "        if (year % 400 == 0 or (year % 4==0 and year % 100 != 0)) and month >= 3:\n",
    "            days += 1\n",
    "        days += day\n",
    "        \n",
    "        return week[(days+3)%7]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "import datetime\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        date = datetime.date(year,month,day)\n",
    "        w = [ \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",\"Sunday\"]\n",
    "        return w[date.weekday()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int)->str:\n",
    "        mnums = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        s = 0  #表示距离1970.12.31有多少天，那天是星期四\n",
    "        sy = 0\n",
    "        for y in range(1971, year):\n",
    "            if (y%400==0) or (y%4==0 and y%100!=0):\n",
    "                sy += 1\n",
    "        s = (year-1971)*365+sy\n",
    "        s += sum(mnums[:month])\n",
    "        if (year%400==0) or (year%4==0 and year%100!=0):\n",
    "            if month > 2:\n",
    "                s += 1\n",
    "        s += day\n",
    "        return week[(s+3)%7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week = [\"Friday\", \"Saturday\", \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\"]\n",
    "        nums = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        cnt = 0\n",
    "        for i in range(1971, year):\n",
    "            if self.judge(i):\n",
    "                cnt += 1\n",
    "            cnt += 365\n",
    "        if self.judge(year):\n",
    "            nums[1] = nums[1] + 1\n",
    "        for i in range(1, month):\n",
    "            cnt = cnt + nums[i - 1]\n",
    "        cnt = cnt + day - 1\n",
    "        return week[cnt % 7]\n",
    "    \n",
    "    def judge(self, year):\n",
    "        return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        偏移 = 365*(year-1971) + (year-1)//4-1970//4\n",
    "        字典 = {0:0, 1:31, 2:59, 3:90, 4:120, 5:151, 6:181, 7:212, 8:243, 9:273, 10:304, 11:334, 12:365}\n",
    "        偏移 += 字典[month-1] + (1 if month > 2 and year!=2100 and year%4 == 0 else 0) + day + 4\n",
    "        偏移 %= 7\n",
    "        日期表 = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "        return 日期表[偏移]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import datetime\n",
    "week=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return week[datetime.date(year,month,day).weekday()]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthday = [31,28,31,30,31,30,31,31,30,31,30,31]  #12个月\n",
    "        days = 0\n",
    "        for y in range(1970,year):\n",
    "            if self.isRun(y) == True:\n",
    "                days+=366\n",
    "            else:\n",
    "                days+=365\n",
    "        if self.isRun(year):\n",
    "            monthday[1] = 29\n",
    "        for m in range(0,month-1):\n",
    "            days+=monthday[m]\n",
    "        days += day\n",
    "        print(days)\n",
    "        return week[(days+2)%7]\n",
    "\n",
    "    def isRun(self,year:int)->bool:\n",
    "        return year % 400 == 0 or (year%4==0 and year %100!=0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "ANS = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, d: int, m: int, y: int) -> str:\n",
    "        # 1900.01.01 为星期一\n",
    "        alls = 1  # 表示当前已经是星期一\n",
    "        # 天数差异\n",
    "        days = d - 1\n",
    "        alls += days\n",
    "\n",
    "        # 月数的天数差异\n",
    "        mouths = 0\n",
    "        for i in range(m - 1):  # 因为表示要过去前一个月的时间,又因为是从一月份开始的,所以是m-1\n",
    "            mouths += DAYS[i]\n",
    "            # 闰年单独考虑:\n",
    "            if i == 1: # 表示包含二月份:\n",
    "                if not y % 4 and (y % 100 or not y % 400):  # 当前是闰年\n",
    "                    mouths += 1\n",
    "\n",
    "        alls += mouths\n",
    "\n",
    "        # 年数的天数差异\n",
    "        # 比当前年数小要减去, 比当前年数大要加上\n",
    "        years = 0\n",
    "        if y < 1900:\n",
    "            for i in range(y, 1900):   # 因为过的是前一年,所以不包含本年(只在月份的地方考虑当前年份的闰平)\n",
    "                # 润\n",
    "                if not i % 4 and (i % 100 or not i % 400):\n",
    "                    years -= 366\n",
    "                # 平\n",
    "                else:\n",
    "                    years -= 365\n",
    "        else:\n",
    "            for i in range(1900, y):\n",
    "                if not i % 4 and (i % 100 or not i % 400):\n",
    "                    years += 366\n",
    "                else:\n",
    "                    years += 365\n",
    "        alls += years\n",
    "\n",
    "        today = alls % 7\n",
    "        \n",
    "        return ANS[today]\n",
    "\n",
    "\n",
    "        \n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",\"Sunday\"][datetime.datetime(year,month,day).weekday()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        return [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"][datetime.date(year, month, day).weekday()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        days=[\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n",
    "        month_days=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        diff_year=year-1-1968\n",
    "        result_days=diff_year*365+diff_year//4\n",
    "        if year%4==0 and year<2100 and month>2:\n",
    "            result_days+=1\n",
    "        result_days+=sum(month_days[:month-1])\n",
    "        result_days+=day\n",
    "        return days[(result_days+2)%7]\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        # 1970 年 12 月 31 日是星期四\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        days = 0\n",
    "        # 输入年份之前的年份的天数贡献\n",
    "        days += 365 * (year - 1971) + (year - 1969) // 4\n",
    "        # 输入年份中，输入月份之前的月份的天数贡献\n",
    "        days += sum(monthDays[:month-1])\n",
    "        if (year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)) and month >= 3:\n",
    "            days += 1\n",
    "        # 输入月份中的天数贡献\n",
    "        days += day\n",
    "\n",
    "        return week[(days + 3) % 7]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        nums = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        weekday_name = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        d, m, y = day, month - 1, year - 1\n",
    "        days_y = y * 365 + y // 4 - y // 100 + y // 400\n",
    "        leap = 1 if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0 else 0\n",
    "        days_m = sum(nums[:m]) + 1 if leap and month > 2 else sum(nums[:m])\n",
    "        days = days_y + days_m + d\n",
    "        return weekday_name[days % 7 - 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]\n",
    "        days = 0\n",
    "        # 输入年份之前的年份的天数贡献\n",
    "        days += 365 * (year - 1971) + (year - 1969) // 4\n",
    "        # 输入年份中，输入月份之前的月份的天数贡献\n",
    "        days += sum(monthDays[:month-1])\n",
    "        if (year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)) and month >= 3:\n",
    "            days += 1\n",
    "        # 输入月份中的天数贡献\n",
    "        days += day\n",
    "\n",
    "        return week[(days + 3) % 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]\n",
    "        days=0\n",
    "        days +=365*(year-1971)+(year-1969)//4\n",
    "        days +=sum(monthDays[:month-1])\n",
    "        if (year % 400==0 or (year %4 ==0 and year %100 !=0)) and month>=3:\n",
    "            days +=1\n",
    "        days +=day\n",
    "        return week[(days+3)%7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        year_num = 0\n",
    "        for i in range(1971, year):\n",
    "            if (i % 4 == 0 and i % 100 != 0) or i % 400 == 0:\n",
    "                year_num += 366\n",
    "            else:\n",
    "                year_num += 365\n",
    "        if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:\n",
    "            tmp = [31,29,31,30,31,30,31,31,30,31,30,31]\n",
    "        else:\n",
    "            tmp = [31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "        dic = {0:\"Friday\",1:\"Saturday\",2:\"Sunday\",3:\"Monday\",4:\"Tuesday\",5:\"Wednesday\",6:\"Thursday\"}\n",
    "        return dic[(year_num+sum(tmp[:month-1])+day-1)%7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]\n",
    "        days = 0\n",
    "        # 输入年份之前的年份的天数贡献\n",
    "        days += 365 * (year - 1971) + (year - 1969) // 4\n",
    "        # 输入年份中，输入月份之前的月份的天数贡献\n",
    "        days += sum(monthDays[:month-1])\n",
    "        if (year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)) and month >= 3:\n",
    "            days += 1\n",
    "        # 输入月份中的天数贡献\n",
    "        days += day\n",
    "\n",
    "        return week[(days + 3) % 7]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        week = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]\n",
    "        days = 0\n",
    "        # 输入年份之前的年份的天数贡献\n",
    "        days += 365 * (year - 1971) + (year - 1969) // 4\n",
    "        # 输入年份中，输入月份之前的月份的天数贡献\n",
    "        days += sum(monthDays[:month-1])\n",
    "        if (year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)) and month >= 3:\n",
    "            days += 1\n",
    "        # 输入月份中的天数贡献\n",
    "        days += day\n",
    "\n",
    "        return week[(days + 3) % 7]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        leap_months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "        \n",
    "        # 1971-01-01为基准日期，是周五\n",
    "        days = [\n",
    "            'Friday',\n",
    "            'Saturday',\n",
    "            'Sunday',\n",
    "            'Monday',\n",
    "            'Tuesday',\n",
    "            'Wednesday',\n",
    "            'Thursday'\n",
    "        ]\n",
    "\n",
    "        diff = 0\n",
    "        \n",
    "        # 处理年\n",
    "        for i in range(1971, year):\n",
    "            if i % 400 == 0 or (i % 4 == 0 and i % 100 != 0):\n",
    "                diff += 1\n",
    "        diff += (year - 1971) * 365\n",
    "\n",
    "        # 处理月\n",
    "        for m in range(month - 1):\n",
    "            if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "                diff += leap_months[m]\n",
    "            else:\n",
    "                diff += months[m]\n",
    "        \n",
    "        # 处理日\n",
    "        diff += day - 1\n",
    "        return days[diff % 7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        date = datetime.datetime.strptime(f'{year}-{month}-{day}','%Y-%m-%d').date()   #字符串转时间\n",
    "        wday = date.weekday( )    # 返回日期对应星期几。\n",
    "        d = dict(zip(range(0,7),[ \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\",\"Sunday\"]))\n",
    "        return d[wday]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:\n",
    "        res = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n",
    "        monthday = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]\n",
    "\n",
    "        day += 365*(year - 1971) + (year - 1969)//4\n",
    "\n",
    "\n",
    "        day += sum(monthday[:month-1])\n",
    "        if month > 2 and ((year % 4 == 0 and year % 100 != 0) or year %400 == 0):\n",
    "            day += 1\n",
    "\n",
    "        return res[(day+3) % 7]\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
